// WorkSchedulerOptionsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "WorkScheduler.h"
#include "WorkSchedulerOptionsDlg.h"


// CWorkSchedulerOptionsDlg dialog

IMPLEMENT_DYNAMIC(CWorkSchedulerOptionsDlg, CDialog)

CWorkSchedulerOptionsDlg::CWorkSchedulerOptionsDlg(CWnd* pParent, WorkSchedulingLogic& schedulingLogic)
	: CDialog(CWorkSchedulerOptionsDlg::IDD, pParent)
	, m_workSchedulingLogic(schedulingLogic)
{
}

CWorkSchedulerOptionsDlg::~CWorkSchedulerOptionsDlg()
{
}

void CWorkSchedulerOptionsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_CHECK_COMPENSATE_IDLE_TIME, m_chkCompensateIdleTime);
}


BEGIN_MESSAGE_MAP(CWorkSchedulerOptionsDlg, CDialog)
END_MESSAGE_MAP()

BOOL CWorkSchedulerOptionsDlg::OnInitDialog()
{
	__super::OnInitDialog();

	SetDlgItemInt(IDC_EDIT_IDLE_THRESHOLD, m_workSchedulingLogic.GetIdleThreasholdSeconds());
	m_chkCompensateIdleTime.SetCheck(m_workSchedulingLogic.GetCompensateForIdleThreshold() ? BST_CHECKED : BST_UNCHECKED);
	return TRUE;
}

void CWorkSchedulerOptionsDlg::OnOK()
{
	m_workSchedulingLogic.SetCompensateForIdleThreshold(m_chkCompensateIdleTime.GetCheck() == BST_CHECKED);
	int idleSeconds = GetDlgItemInt(IDC_EDIT_IDLE_THRESHOLD);
	if (idleSeconds > 0)
		m_workSchedulingLogic.SetIdleThresholdSeconds(idleSeconds);
	else
	{
		AfxMessageBox(_T("Invalid value set for idle time"));
		return;
	}

	__super::OnOK();
}